<div class="flexigrid">
    <div class="mDiv">
        <div class="ftitle">
            &nbsp;
        </div>
        <div title="Minimize/Maximize" class="ptogtitle">
            <span></span>
        </div>
    </div>
    <div id="main-table-box">
        <div class="tDiv tDiv4">
            <div class="row">
                <div class="twelve columns text-right">
                    <a href="<?php echo base_url(); ?>admin/agregarVehiculo" class="small button radius success"><?php echo $this->lang->line('add_vehicle'); ?></a>
                </div>
            </div>
            <div class="row">
                <div class="twelve columns">
                    <p>Seleccione una categoria:</p>
                    <select id="carroceria" name="carroceria">
                        <?php
                        foreach ($carrocerias as $carroceria) {
                            if ($this->c == $carroceria->id) {
                                $ctipo = $carroceria->tipo;
                                echo '<option value="' . $carroceria->id . '" selected>' . $carroceria->tipo . '</option>';
                            } else {
                                echo '<option value="' . $carroceria->id . '">' . $carroceria->tipo . '</option>';
                            }
                        }
                        ?>
                    </select>
                </div>
            </div><br/>
            <div class="row">
                <div class="large-12 columns centered">
                    <div class="row">
                        <?php if (empty($results)): ?>
                            <div data-alert="" class="alert-box alert text-center">
                                Aun no hay vehiculos registrados en la categoria <?php echo $ctipo; ?>
                            </div>
                        <?php endif; ?>
                        <?php foreach ($results as $data): ?>
                            <div id="vehicle<?php echo $data->id; ?>" class="large-2 mobile-two columns">
                                <img src="<?php echo base_url() . 'cars/thumbs/' . $data->imagen1; ?>"/>
                                <div class="panel">
                                    <h5><?php echo $data->marca . ' ' . $data->modelo; ?></h5>
                                    <h6 class="subheader"><?php echo $data->anno; ?></h6>
                                    <h6 class="subheader2">$<?php echo $data->precio; ?></h6>
                                    <h6 class="subheader2">
                                        <a href="editarVehiculo?id=<?php echo $data->id; ?>" class="small button success">Editar</a>
                                        <a href="javascript:void(0);" id="<?php echo $data->id; ?>" class="delete small button">Borrar</a>
                                    </h6>
                                </div>
                            </div>
                        <?php endforeach; ?>
                    </div>
                    <div class="row">
                        <div class="twelve columns">
                            <ul class="pagination">
                                <?php echo $links; ?>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="deleteModal" class="reveal-modal">
    <p class="lead">Esta seguro que quiere borrar este vehiculo?</p>
    <p><a href="#" class="small button success radius">Si</a> <a href="#" class="small button secondary radius">No</a></p>
    <a class="close-reveal-modal">&#215;</a>
</div>

<script>
    $(document).ready(function() {
        $('#carroceria').change(function() {
            window.location = 'listaVehiculos?c=' + $(this).val();
        });
        $(".delete").click(function() {
            $('#load').fadeIn();
            var id = $(this).attr("id");
            var string = 'id=' + id;
            var vehiculo = $('#vehicle' + id).find('h5').text();
            var anno = $('#vehicle' + id).find('.subheader').text();
            console.log(vehiculo);
            if (confirm("Desea borrar " + vehiculo + ' ' + anno + "?")) {
                $.ajax({
                    type: "POST",
                    url: "<?php echo base_url(); ?>admin/borrarVehiculo",
                    data: string,
                    cache: false,
                    success: function() {
                        $('#vehicle' + id).slideUp('slow', function() {
                            $(this).remove();
                            window.location.href = "<?php echo base_url(); ?>admin/listaVehiculos?c=<?php echo $this->c; ?>";
                        });
                    }
                });
            }
            return false;
        });

    })
</script>